home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
smaltalk
/
stv.lha
/
STV
/
st_v
/
util
/
STVUTIL5.ZIP
/
SCLPN.MTH
< prev
next >
Wrap
Text File
|
1993-02-07
|
9KB
|
290 lines
"
Implementation of a GraphPane which handles the scrollbars correct.
(C) 1991, Roelof Osinga
Although this is copyrighted code you are free to use it as pleased. The
only restriction is that the copyright notice is maintained.
"
! Rectangle methods !
areaPoint: aPoint
"Answer true if aPoint is within the area of
the receiver, else answer false."
^(aPoint x >= leftTop x) and: [(aPoint x <= rightBottom x)
and: [(aPoint y >= leftTop y) and: [aPoint y <=rightBottom y]]]! !
"define class"
FreeDrawPane subclass: #MyGraphPane
instanceVariableNames: 'eraseReturn'
classVariableNames: ''
poolDictionaries:
'CharacterConstants ColorConstants WinConstants DrawingModeConstants '!
! MyGraphPane methods !
backup: aBitmap
"Change the backup to a new bitmap"
| extent |
backup notNil ifTrue: [
extent := backup extent.
GDILibrary setViewportOrg: graphicsTool handle
x: 0
y: 0.
backup release].
backup := aBitmap.
topCorner := nil.
self updateRectangle; display! !
! MyGraphPane methods !
contents
"Answer the receiver's backup form."
^backup! !
! MyGraphPane methods !
contents: aBitmap
"Change the backup to a new bitmap"
self backup: aBitmap! !
! MyGraphPane methods !
erase
"Erase the bitmap and pane"
backup notNil
ifTrue: [backup pen erase].
^super erase! !
! MyGraphPane methods !
scrollingRectangle
"Private - Answer the rectangle or the
boundingBox of the image."
backup notNil
ifTrue: [^backup boundingBox]
ifFalse: [^rectangle expandBy: (rectangle extent // 2)]! !
! MyGraphPane methods !
scrollingRectangleRange
"Private - Answer the rectangle in which the
topCorner must lie."
| box |
^(self scrollingRectangle insetBy: rectangle)
merge: (0@0 extent: 0@0)! !
! MyGraphPane methods !
setScrollRanges
"Private - Set the ranges for the horizontal and vertical
scroll bars."
| rangeRect minHorz maxHorz minVert maxVert |
rangeRect := self scrollingRectangleRange.
minHorz := rangeRect left.
maxHorz := rangeRect right.
minVert := rangeRect top.
maxVert := rangeRect bottom.
(self style bitAnd: WsHscroll) = 0
ifTrue: [minHorz := maxHorz := 0].
(self style bitAnd: WsVscroll) = 0
ifTrue: [minVert := maxVert := 0].
UserLibrary
setScrollRange: self asParameter
bar: SbHorz
min: minHorz
max: maxHorz
redraw: false.
UserLibrary
setScrollRange: self asParameter
bar: SbVert
min: minVert
max: maxVert
redraw: false! !
! MyGraphPane methods !
updateRectangle
"Private - Update rectangle to be the same
as the Windows."
rectangle := self rectangle.
backup isNil
ifTrue: [
graphicsTool notNil ifTrue: [
graphicsTool
width: rectangle width;
height: rectangle height]]
ifFalse: [graphicsTool notNil ifTrue: [
graphicsTool
width: backup width;
height: backup height]].
children size ~= 0
ifTrue: [
children do: [:each |
each updateRectangle]].
self setScrollRanges.
topCorner isNil ifTrue: [topCorner := "1@1 "0@0].
self updateSliders.
self event: #resize! !
!MyGraphPane methods !
wmErasebkgnd: wordInteger with: longInteger
"Private - Process the Win erase background message."
(eraseReturn = nil)
ifTrue: [^nil]
ifFalse: [eraseReturn := nil. ^0]! !
!MyGraphPane methods !
scrollTopCorner: aPoint
"Private - Move the contents of the receiver
pane by extent aPoint."
| oldCorner scrollRect delta |
delta := aPoint.
oldCorner := topCorner deepCopy.
topCorner := topCorner - delta.
oldCorner = topCorner ifTrue: [^self].
((scrollRect := self scrollingRectangleRange) areaPoint: topCorner) ifFalse: [
(scrollRect left > topCorner x) ifTrue: [topCorner x: scrollRect left].
(scrollRect right < topCorner x) ifTrue: [topCorner x: scrollRect right].
(scrollRect top > topCorner y) ifTrue: [topCorner y: scrollRect top].
(scrollRect bottom < topCorner y) ifTrue: [topCorner y: scrollRect bottom].
topCorner = oldCorner ifTrue: [
topCorner := oldCorner deepCopy.
^self].
delta := oldCorner - topCorner.
].
UserLibrary scrollWindow: handle
xAmount: delta x
yAmount: delta y
lpRect: nil
clipRect: nil.
GDILibrary offsetViewportOrg: graphicsTool handle
x: delta x
y: delta y.
UserLibrary updateWindow: handle.
eraseReturn := 0! !
"define class"
BitEditor subclass: #RoBitEditor
instanceVariableNames:
'pane '
classVariableNames: ''
poolDictionaries:
'WinConstants ColorConstants '!
! RoBitEditor methods !
openOn: aGraphPane
"Open a BitEditor on aGraphPane."
self openOn: aGraphPane
clipRect: (0 @ 0 extent: aGraphPane contents extent)! !
! RoBitEditor methods !
openOn: aGraphPane clipRect: aRect
"Open a BitEditor on aBitmap."
| groupPane size imageSize |
scale := 8.
pane := aGraphPane.
imageForm := aGraphPane contents.
imageSize := (aRect extent min: imageForm extent) min:
(Display width - 80 // scale @
(Display height - 20 // scale)).
imageRect := aRect origin extent:
(aRect extent min: imageSize).
imageSize := imageSize * scale + (5 @ 5).
size := 76 @ (300 max: imageSize y).
copy := Bitmap screenExtent: aRect extent.
copy pen copyBitmap: aGraphPane contents
from: aRect
at: 0 @ 0.
self label: 'BitEditor'.
self addSubpane: (
GraphPane new
model: self;
when: #display perform: #displayImage:;
style: GraphPane noScrollBarsFrameStyle;
framingBlock: [: box |
box origin extent: (size x @ (box height // 2))]).
self addSubpane:
(groupPane := GroupPane new
framingBlock: [: box |
box origin x @ (box origin y + (box height // 2))
extent: (size x @ (box height // 2))]).
groupPane addSubpane:
(Button new
model: self;
contents: 'Save';
pushButton;
when: #clicked perform: #save:;
framingBlock: [: box |
(box origin x + (box width // 6)) @ (box origin y + (box height // 6))
extent: (box width * 2 // 3) @ (box height // 3)]).
groupPane addSubpane:
(Button new
model: self;
contents: 'Exit';
pushButton;
when: #clicked perform: #exit:;
framingBlock: [: box |
(box origin x + (box width // 6)) @ (box origin y + (box height // 2))
extent: (box width * 2 // 3) @ (box height // 3)]).
self addSubpane:
(GraphPane new
owner: self;
when: #getMenu perform: #editMenu:;
when: #display perform: #displayBits:;
when: #button1Down perform: #changeBits:;
when: #button1Move perform: #changeBits:;
style: GraphPane noScrollBarsFrameStyle;
framingBlock: [: box |
box origin x + (size x @ 0) extent: (
(box width - size x) @ box height)]).
windowSize := 76 + imageSize x + 2 @
(( 300 max: imageSize y) + SysFont height + 6).
self openWindow.
self menuWindow addMenu: (
Menu colorMenu: self selector: #colorSelected:)! !
! RoBitEditor methods !
save: aButtton
imageForm pen copyBitmap: copy
from: copy boundingBox
at: imageRect origin.
pane display! !
"define class"
FreeDrawing subclass: #MyFreeDrawing
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries:
'WinConstants ColorConstants '!
! MyFreeDrawing methods !
backupRelative: aPoint
"Private - Answer a point relative to the pane's backup
from aPoint."
^aPoint! !
! MyFreeDrawing methods !
bitEdit
"Prompt the user for a rectangle and open a BitEditor
on the bitmap associated with the rectangle."
| aRect |
aRect := Display rectangleFromUser mapToWindow: pane.
aRect moveBy: pane topCorner - (1@1).
RoBitEditor new openOn: pane
clipRect: aRect! !
! MyFreeDrawing methods !
open
"Open a Free Drawing window."
self label: 'FreeDrawing';
when: #activate perform: #activate:;
addSubpane: (
pane := MyGraphPane new
owner: self;
when: #getMenu perform: #modeMenu:;
when: #getContents perform: #initPen:;
when: #button1Down perform: #mouseDown:;
yourself).
self openWindow.
self menuWindow addMenu: self optionsMenu.
self menuWindow addMenu: (
Menu colorMenu: self selector: #colorSelected:)! !